﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Problem007
{
    static class Program
    {
        private const int primesToSkip = 10000;

        static void Main()
        {
            Console.Write(GeneratePrimes(2, Int32.MaxValue - 1).Skip(primesToSkip).First());

            Console.ReadKey();
        }

        private static IEnumerable<int> GeneratePrimes(int start, int count)
        {
            var primes = from number
                             in Enumerable.Range(start, count)
                         where number.IsPrime()
                         select number;

            return primes;
        }

        private static readonly List<int> knownPrimes = new List<int>();

        private static bool IsPrime(this int number)
        {
            var isPrime = knownPrimes.TrueForAll(x => 0 != (number%x));

            if(isPrime)
                knownPrimes.Add(number);

            return isPrime;
        }
    }
}
